package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * PROJECT_NAME: test
 * NAME: ShoppingCartController
 *
 * @AUTHOR: YAN6D0N6SH3N6
 * DATETIME: 2023/7/24 21:14  ᖗ ✿ ᖘ
 * DESCRIPTION : 购物车
 */
@Slf4j
@Api(tags = "C端-购物车信息表现层接口") //@Api:用户描述类的相关信息
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {
    @Resource
    private ShoppingCartService shoppingCartService;


    @ApiOperation("添加购物车")
    @PostMapping("/add")
    public Result insertShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        log.info("【添加购物车】要添加的菜品或套餐:{}", shoppingCartDTO);
        shoppingCartService.insertShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    @ApiOperation("查看购物车")
    @GetMapping("/list")
    public Result<List<ShoppingCart>> selectShoppingCart() {
        log.info("【查看购物车】");
        return shoppingCartService.selectShoppingCart();
    }

    @ApiOperation("删减购物车商品")
    @PostMapping("/sub")
    public Result subShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("【删减购物车商品】要删减的菜品或套餐:{}", shoppingCartDTO);
        shoppingCartService.subShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    @ApiOperation("清空购物车商品")
    @DeleteMapping("/clean")
    public Result clearShoppingCart(){
        log.info("【清空购物车】");
        shoppingCartService.clearShoppingCart();
        return Result.success();
    }

}
